From 876a04a795fcb179e0dc802e260353012c4890f9 Mon Sep 17 00:00:00 2001
From: Maxim Kochetkov <adobegitler@gmail.com>
Date: Thu, 28 Jan 2021 08:12:57 +0300
Subject: [PATCH] Use pkg-config to get PROJ version if available

In case of cross-compile AC_PROJ_VERSION([POSTGIS_PROJ_VERSION]) fails.
So try to get version by pkg-config first

Signed-off-by: Maxim Kochetkov <fido_max@inbox.ru>
Fetch from: https://github.com/postgis/postgis/commit/671a878982550e3c590d642620a6621b52c230c7.patch
---
 configure.ac | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 86e1597ee..016f81c7d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -866,6 +866,7 @@ elif test ! -z "$PKG_CONFIG"; then
 		[
 			PROJ_CPPFLAGS="$PROJ_CFLAGS"
 			PROJ_LDFLAGS="$PROJ_LIBS"
+			POSTGIS_PROJ_VERSION=`$PKG_CONFIG proj --modversion | sed 's/\([[0-9]]\).*\([[0-9]]\).*\([[0-9]]\)/\1\2/'`
 		],
 		[
 			PROJ_LDFLAGS="-lproj"
@@ -887,8 +888,10 @@ AC_CHECK_HEADER([proj_api.h],
 		)]
 	)
 
-dnl Return the PROJ.4 version number
-AC_PROJ_VERSION([POSTGIS_PROJ_VERSION])
+dnl Return the PROJ.4 version number if not detected by pkg-config
+if test "x$POSTGIS_PROJ_VERSION" = "x"; then
+	AC_PROJ_VERSION([POSTGIS_PROJ_VERSION])
+fi
 AC_DEFINE_UNQUOTED([POSTGIS_PROJ_VERSION], [$POSTGIS_PROJ_VERSION], [PROJ library version])
 AC_SUBST([POSTGIS_PROJ_VERSION])
 CPPFLAGS="$CPPFLAGS_SAVE"
-- 
2.30.0

